package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Department;
import cn.wolfcode.domain.Employee;
import cn.wolfcode.mapper.DepartmentMapper;
import cn.wolfcode.mapper.EmployeeMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IDepartmentService;
import cn.wolfcode.service.IEmployeeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DeparmentServiceImpl extends ServiceImpl<DepartmentMapper,Department> implements IDepartmentService {
    //初始化mapper对象
    private DepartmentMapper departmentMapper;

    @Autowired
    public void setDepartmentMapper(DepartmentMapper departmentMapper) {
        this.departmentMapper = departmentMapper;
    }

    @Transactional
    @Override
    public void delete(Long id) {
        departmentMapper.deleteById(id);
    }

    @Transactional
    @Override
    public void insert(Department department) {
        departmentMapper.insert(department);
    }

    @Override
    public Department get(Long id) {
        return departmentMapper.selectById(id);
    }

    @Override
    public List<Department> listAll() {
        return departmentMapper.selectList(null);
    }

    @Transactional
    @Override
    public void update(Department department) {
        departmentMapper.update(department,null);
    }

    @Override
    public IPage<Department> query(QueryObject qo) {
        Page<Department> page = new Page<>(qo.getCurrentPage(), qo.getPageSize());
        QueryWrapper<Department> wrapper = Wrappers.<Department>query();
        return super.page(page,wrapper);
    }
}
